// fast4j - Fast & Agile Service Tools for Java
// Copyright (C) 2007 Alexandre ROMAN
//
// This library is free software; you can redistribute it and/or
// modify it under the terms of the GNU Lesser General Public
// License as published by the Free Software Foundation; either
// version 2.1 of the License, or (at your option) any later version.
//
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
// Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public
// License along with this library; if not, write to the Free Software
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA

// $Id: ServiceBridgeContextHolder.java 40 2007-03-29 20:57:50Z alexandre.roman $

package fast4j.ejbbridge;

import java.util.HashMap;
import java.util.Map;

/**
 * Service context holder. This class can be used from the server side, to get
 * values from the current service call context. Theses values are exposed by a
 * {@link Map}. Any modifications made to this {@link Map} will return to the
 * client through a {@link ServiceResult}. This implementation uses a
 * {@link ThreadLocal} to store values from the current service call.
 * @author alexandre.roman
 */
public final class ServiceBridgeContextHolder {
    private static final ThreadLocal HOLDER = new ThreadLocal() {
        protected Object initialValue() {
            return new HashMap();
        }
    };
    
    /**
     * Returns current service call context values.
     */
    public static Map get() {
        return (Map) HOLDER.get();
    }
    
    /**
     * Destroys thread-local {@link Map}. This method is automatically called
     * to free any resources contained in this class.
     */
    public static void release() {
        HOLDER.remove();
    }
}
